package com.newland.zxy.config;

import com.netflix.loadbalancer.NoOpPing;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : zhangxuyuan
 * @Project: springcloudoauth2
 * @Package com.newland.zxy.config
 * @date Date : 2021年02月05日 10:24
 *
 *
 * SpringSecurity相关配置
 */
@Configuration
public class MySecurityConfigure extends WebSecurityConfigurerAdapter {



    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }


    @Bean
    public PasswordEncoder passwordEncoder()
    {
        return NoOpPasswordEncoder.getInstance();
    }


    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        UserDetails userDetails = User.withUsername("zxy")
                .password("123")
                .authorities("user", "testUser")
                .build();
        auth.inMemoryAuthentication()
                .withUser(userDetails);
    }
}
